#!/bin/bash

set -e

#如果没有build目录，则创建build
if [ ! -d `pwd`/build ]; then
    mkdir `pwd`/build
fi

#清空build
rm -rf `pwd`/build/*

cd `pwd`/build &&
    cmake .. &&
    make

#回到项目根目录
cd ..

#创建一个文件，存放头文件
if [ ! -d /usr/include/myMuduo ]; then
    mkdir /usr/include/myMuduo
fi

#把头文件拷贝到 /usr/include/myMuduo    生成的动态库拷贝到 /usr/lib    PATH
for header in `ls ./include/*.h`
do
    cp $header /usr/include/myMuduo
done

cp `pwd`/lib/libmyMuduo.so /usr/lib

ldconfig